package com.gosophia.dataDictionary.action;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.OrderCondition;
import com.gosophia.commons.web.action.BaseAjaxAction;
import com.gosophia.dataDictionary.dto.DataEntryDTO;
import com.gosophia.dataDictionary.ws.DataDictionaryWebService;

/**
 * 刷列表
 * 
 * @author tianchunyu
 * 
 */

@Controller
@Scope("prototype")
public class ListDataEntriesAction extends BaseAjaxAction<DataEntryDTO> {

	/**
     * 
     */
	private static final long serialVersionUID = 1L;

	@Override
	public DataEntryDTO getDetailData() {
		return this.detailData;
	}

	@Autowired
	private DataDictionaryWebService dataDictionaryWebService;

	@Override
	public String _execute() throws Exception {
		if(orderConditions != null && orderConditions.size()>=1) {
            for(int i = orderConditions.size() - 1;i >= 0;--i)
            {
                OrderCondition orderCondition = orderConditions.get(i);
                if(orderCondition.getPropertyName() == null || orderCondition.getPropertyName().length() <= 0
                        || orderCondition.getOrder() == null || orderCondition.getOrder().length() <= 0) 
                    orderConditions.remove(i);
            }
        }
        
        if(orderConditions == null || orderConditions.size() <= 0)
        {
            orderConditions = new ArrayList<OrderCondition>();
            //默认排序：词条名称
            orderConditions.add(OrderCondition.asc("entryNameCN"));
        }

		this.page = dataDictionaryWebService.findEntriesByPage(this.page
				.getPageNo(), this.page.getPageSize(), this.searchString,
				this.orderConditions);
		String rsltCode = this.page.getResult().size() == 0 ? "1" : "0";
		super.getRequestResult().setRsltCode(rsltCode);
		return SUCCESS;
	}

}
